package OjPracticeWithMyselfNote.LinkedList;

public class deleteRepetition {
    static class ListNode {
        int val;
        ListNode next;
        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode deleteDuplicates (ListNode head) {
        ListNode cur = head;
        ListNode newHead = new ListNode(1);
        ListNode tempHead = newHead;
        while(cur!=null){
            if(cur.next!=null&&cur.val==cur.next.val){
                while(cur.next!=null&&cur.val==cur.next.val) {
                    cur=cur.next;
                }
                cur=cur.next;
            }else{
                tempHead.next = cur;
                tempHead = tempHead.next;
                cur=cur.next;
            }
        }
        tempHead.next=null;
        return newHead.next;
    }
}
